import axios from '@/libs/api.request'
import { getToken } from '@/libs/util'
import { downloadURL } from '@/config/downloadUrl.js'
// --------------------------------------- 主接口 ---------------------------------
// 新建或修改企业资质
export const postCompany = (data) => {
    return axios.request({
        url: '/ui/customs/declare/addOrEditCopLimit',
        data: data,
        method: 'post'
    })
}
// 删除企业资质
export const delCompany = (data) => {
    return axios.request({
        url: '/ui/customs/declare/deleteCopLimitByIds',
        data: data,
        method: 'post'
    })
}
// 根据id查询企业资质
export const getCompanyId = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryCopLimitByDeclareId',
        data: data,
        method: 'post'
    })
}
// 新建或修改使用人
export const postUser = (data) => {
    return axios.request({
        url: '/ui/customs/declare/addOrEditCopLimit',
        data: data,
        method: 'post'
    })
}
// 删除使用人
export const delUser = (data) => {
    return axios.request({
        url: '/ui/customs/declare/deleteDecUserByIds',
        data: data,
        method: 'post'
    })
}
// 根据id查询使用人
export const getUserId = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryDecUserByDeclareId',
        data: data,
        method: 'post'
    })
}
// 新增/修改报关单数据
export const postDeclare = (data) => {
    return axios.request({
        url: '/ui/customs/declare/addOrEditDeclare',
        data: data,
        method: 'post'
    })
}
// 删除报关单数据
export const delDeclare = (data) => {
    return axios.request({
        url: '/ui/customs/declare/deleteDeclareById',
        data: data,
        method: 'post'
    })
}
// 生成报关资料
export const buildDoc = (data) => {
    return axios.request({
        url: '/ui/dataFileDownload/exportDeclareXls',
        params: data,
        method: 'get'
    })
}
// 选择订单新建报关单
export const changeOrder = (data) => {
    return axios.request({
        url: '/ui/customs/declare/generateDeclareByBusiness',
        data: data,
        method: 'post'
    })
}
// 根据xls模板导入报关单数据
export const importExcelData = (data, type) => {
    return axios.request({
        url: '/ui/customs/declare/inExportXlsDeclare?businessType=' + type,
        data: data,
        method: 'post'
    })
}
// 导出 报关单
export const exportExcelData = (data) => {
    return axios.request({
        url: '/ui/customs/declare/downLoadDeclareFiles',
        params: data,
        method: 'get'
    })
}
// 查询报关单(进口，出口，进境，出境，以上四种查询均为此接口)
export const getDeclareList = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryDeclareByCondition',
        data: data,
        method: 'post'
    })
}
// 根据报关id 查询报关单数据，回显在查看和修改上
export const getDeclareId = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryDeclareById',
        data: data,
        method: 'post'
    })
}
// 报文记录查询
export const getHistory = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryMessageRecord',
        data: data,
        method: 'post'
    })
}
// 申报报关单/批量申报报关单
export const examineDeclareList = (data) => {
    return axios.request({
        url: '/ui/customs/declare/sendDeclareToSingleWindow',
        data: data,
        method: 'post'
    })
}
// 统一保存 报关单数据
export const saveAllData = (data) => {
    return axios.request({
        url: '/ui/customs/declare/unifySaveDeclare',
        data: data,
        method: 'post'
    })
}
// 审核配置
export const examineOpea = (data) => {
    return axios.request({
        url: '/ui/customs/declare/updateExamine',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 集装箱接口 ---------------------------------
// 新增或修改报关集装箱
export const postContainer = (data) => {
    return axios.request({
        url: '/ui/customs/declareContainer/addOrEditContainer',
        data: data,
        method: 'post'
    })
}
// 批量删除集装箱
export const delAllContainer = (data) => {
    return axios.request({
        url: '/ui/customs/declareContainer/deleteContainerByIds',
        data: data,
        method: 'post'
    })
}
// 导入集装箱数据
export const batchimportContainer = (data, declareId) => {
    return axios.request({
        url: '/ui/customs/declareContainer/importCustomsDeclareContainer?declareId=' + declareId,
        data: data,
        method: 'post'
    })
}
// 分页查询集装箱数据
export const getContainerList = (data) => {
    return axios.request({
        url: '/ui/customs/declareContainer/queryContainerByCondition',
        data: data,
        method: 'post'
    })
}
// 根据id查询集装箱数据
export const getContainerId = (data) => {
    return axios.request({
        url: '/ui/customs/declareContainer/queryContainerById',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 报关单单证接口 ---------------------------------
// 新增修改单证信息
export const postDoc = (data) => {
    return axios.request({
        url: '/ui/customs/declareDoc/addOrEditDoc',
        data: data,
        method: 'post'
    })
}
// 原产地关系单证代码为Y/E/R/F/J的才可以录入对应关系---暂时不做
export const getDocOrigin = (data) => {
    return axios.request({
        url: '/ui/customs/declareDoc/countryDocOrigin',
        data: data,
        method: 'post'
    })
}
// 批量删除单证信息
export const delDoc = (data) => {
    return axios.request({
        url: '/ui/customs/declareDoc/deleteDocByIds',
        data: data,
        method: 'post'
    })
}
// 单证信息分页查询
export const getDocList = (data) => {
    return axios.request({
        url: '/ui/customs/declareDoc/queryDocByCondition',
        data: data,
        method: 'post'
    })
}
// 单证信息回显数据
export const getDocId = (data) => {
    return axios.request({
        url: '/ui/customs/declareDoc/queryDocById',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 商品明细接口 ---------------------------------
// 根据商品编码模糊查询商品信息
export const getGoodsListInfo = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/getCustomsHsCodeByCode',
        data: data,
        method: 'post'
    })
}
// 根据商品编码获取商品要素title
export const getGoodsCode = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/getCustomsHsCodeElementDocByCodeTs',
        data: data,
        method: 'post'
    })
}
// 根据企业物料编号查询商品信息
export const getDetailGoods = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/getGoodsDetailsByLikeDetailNo',
        data: data,
        method: 'post'
    })
}
// 批量导入报关商品明细
export const importDetailGoods = (data, declareId, businessType) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/importCustomsDeclareGoodsByExcel?declareId=' + declareId + '&businessType=' + businessType,
        data: data,
        method: 'post'
    })
}
// 根据报关单id查询商品明细
export const getGoodsId = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/queryDeclareGoods',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 商品许可证接口 ---------------------------------
// 新增商品许可证信息
export const postGoodsDoc = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/addGoodsLimit',
        data: data,
        method: 'post'
    })
}
// 新增商品许可证VIN信息
export const postGoodsDocVin = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/addGoodsLimitVin',
        data: data,
        method: 'post'
    })
}
// 批量删除商品许可证信息
export const delGoodsDoc = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/delGoodsLimitByIds',
        data: data,
        method: 'post'
    })
}
// 批量删除商品许可证VIN信息
export const delGoodsDocVin = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/addGoodsLimitVin',
        data: data,
        method: 'post'
    })
}
// 编辑商品许可证信息
export const putGoodsDoc = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/editGoodsLimit',
        data: data,
        method: 'post'
    })
}
// 编辑商品许可证VIN信息
export const putGoodsDocVin = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/editGoodsLimitVin',
        data: data,
        method: 'post'
    })
}
// 根据报关单商品id查询商品许可证信息
export const getGoodsDocId = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/queryCustomsGoodsLimitList',
        data: data,
        method: 'post'
    })
}
// 根据报关单商品id查询商品许可证VIN信息
export const getGoodsDocVinId = (data) => {
    return axios.request({
        url: '/ui/declaremanager/declareGoods/queryCustomsGoodsLimitVinList',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 随附单据接口 ---------------------------------
// 删除文件
export const delDataFile = (data) => {
    return axios.request({
        url: '/ui/customs/declare/deleteFile',
        data: data,
        method: 'post'
    })
}
// 下载随附单据
// export const downFile = (data) => {
//     return axios.request({
//         url: '/ui/customs/declare/downFile',
//         data: data,
//         method: 'post'
//     })
// }
// EXCEL 转 PDF
export const excelTopdf = (data) => {
    return axios.request({
        url: '/ui/customs/declare/excel2Pdf',
        data: data,
        method: 'post'
    })
}
// 根据declareId 查找相应的文件数据
export const queryFile = (data) => {
    return axios.request({
        url: '/ui/customs/declare/queryFile',
        data: data,
        method: 'post'
    })
}
// 上传随附单据
export const uploadFile = (data) => {
    return axios.request({
        url: '/ui/customs/declare/uploadFile',
        data: data,
        method: 'post'
    })
}
// 下载随附单据
export const downloadFile = (data) => {
    return axios.request({
        url: '/ui/dataFileDownload/downloadFile',
        data: data,
        method: 'post'
    })
}
// 查询 附件类型
export const getAccessoryType = (data) => {
    return axios.request({
        url: '/customs/business/getAccessoryType',
        method: 'get'
    })
}
// --------------------------------------- 查询进口订单模板 ---------------------------------
// 查询订单
export const getBusiness = (data) => {
    return axios.request({
        url: '/customs/business/queryBusiness',
        data: data,
        method: 'post'
    })
}
// --------------------------------------- 查询基本数据类型 ---------------------------------
export const getBasicData = (data) => {
    return axios.request({
        url: '/ui/commonbasicdata/basicData/getCustomsBasicDataVo',
        data: data,
        method: 'post'
    })
}
// ---- 订单生成报关单
export const getBusToDec = ({ businessId }) => {
    return axios.request({
        url: '/customs/business/sendBusinessToDeclare',
        data: {
            businessId: businessId
        },
        method: 'post'
    })
}

// 根据企业物料ID 查询商品信息
export const getDetailIdToGoods = (data) => {
    return axios.request({
        url: '/customs/businessGoods/getGoodsDetailsByLikeDetailNo',
        data: data,
        method: 'post'
    })
}

// 确认 & 取消确认
export const changeConfirmStatus = (data) => {
    return axios.request({
        url: '/ui/customs/declare/changeConfirmStatus',
        params: data,
        method: 'post'
    })
}

/* 打印文件 */
export const onPrint = (data) => {
    return axios.request({
        url: '/ui/customs/declare/onPrint',
        data: data,
        method: 'post'
    })
}
/* 打印海运舱单文件 */
export const onShipPrint = (data) => {
    return axios.request({
        url: '/customs/manifest/printShipManifest',
        params: data,
        method: 'get'
    })
}

/**
 * 批量生成报关单或放行通知书(生成至文件服务器)
 * @param {String} declareIds 报关单id
 * @param {String} type DEC：报关单，NOTI：放行通知书
 */
export function postSwPdf (declareIds, type = 'DEC') {
    return axios.request({
        url: '/ui/customs/declare/postSwPdf',
        params: {
            param: {
                declareIds,
                type
            }
        },
        method: 'post'
    })
}

/**
 * 查询回执报文是否‘直接申报成功’
 * @param {Number} id 报关单id
 */
export function checkRecordStatus ({
    id,
    pageNum = 0,
    pageSize = 100
}) {
    return axios.request({
        url: '/ui/customs/declare/messageRecordSuccessStatus',
        method: 'post',
        data: {
            id,
            pageNum,
            pageSize
        }
    })
}

/* 打印文件 */
export const printWhole = (url) => {
    return axios.request({
        url,
        method: 'get'
    })
}

/**
 * 退回报关单
 */
export function declareSendBack (declareId) {
    return axios.request({
        url: '/ui/customs/declare/sendBack',
        method: 'post',
        params: {
            declareId
        }
    })
}

/**
 * 报关单生产公路舱单
 * @param {String}} declareIds
 */
export function createManifest (declareIds) {
    return axios.request({
        url: '/ui/customs/declare/createManifest',
        method: 'post',
        params: {
            declareIds
        }
    })
}
export function revertManifest (declareIds) {
    return axios.request({
        url: '/ui/customs/declare/revert',
        method: 'post',
        params: {
            declareIds
        }
    })
}

// 批量下载 正本报关单、核注清单截图的单一窗口PDF
export function batchDownloadSwPDF (data) {
    let params = []
    Object.keys(data).forEach(key => {
        data[key] && params.push(`${key}=${data[key]}`)
    })
    params.push(`Authorization=${getToken()}`)
    window.open(`${downloadURL}/ui/customs/declare/dataFileDownload/batchDownload?${params.join('&')}`)
}
